# pragma once

# include "cpp_tools_Headers.h"

namespace cpp_tools
{
    template <typename Derived>
    Eigen::VectorXd cumsum(const Eigen::MatrixBase<Derived>& y) {
        // 检查输入
        if (y.size() == 0) {
            throw std::invalid_argument("Input array 'y' must not be empty.");
        }

        // 计算累积和
        Eigen::VectorXd result(y.size());
        result.setZero();
        result(0) = y(0);
        for (int i = 1; i < y.size(); ++i) {
            result(i) = result(i - 1) + y(i);
        }

        return result;
    }
} // namespace cpp_tools
